package com.liangzhong.modules.talent.mediator
{
	import com.common.queueloader.QueueLoader;
	import com.common.queueloader.QueueLoaderEvent;
	import com.common.queueloader.QueueVo;
	import com.common.utils.Reflection;
	import com.global.GlobalDef;
	import com.liangzhong.constants.ResourceConst;
	import com.liangzhong.events.AppEventDispatcher;
	import com.liangzhong.events.ClubEvent;
	import com.liangzhong.events.PlayerCenterEvent;
	import com.liangzhong.events.TalentEvent;
	import com.liangzhong.manager.ResourceManager;
	import com.liangzhong.mediator.ModuleMediator;
	import com.liangzhong.proxyconstant.PlayerCenter.PlayerCenterConstant;
	import com.liangzhong.proxyconstant.club.ClubProxyConstant;
	import com.liangzhong.proxyconstant.talent.TalentProxyConstant;
	import com.lz.football.module.base.IModuleView;
	import com.lz.football.module.club.IClubView;
	
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	import flash.events.Event;
	
	import org.puremvc.as3.interfaces.INotification;
	
	public class TalentMediator extends ModuleMediator
	{
		public static const MediatorName :String = "TalentMediator";
		public function TalentMediator(mediatorName:String=null, viewComponent:Object=null, param:Object=null)
		{
			super(mediatorName, viewComponent, param);
		}
		
		/**
		 *获取 实例 
		 * @return 
		 * 
		 */		
		public function get clubView():DisplayObjectContainer
		{
			return viewComponent as DisplayObjectContainer;
		}
		/**
		 *添加事件 
		 * 
		 */		
		override public function addEventListeners():void
		{
			
		}
		
		/**
		 * 重置天赋  
		 * @param event
		 * 
		 */
		private function onResetTalentHandler(event:TalentEvent):void
		{
			this.sendNotification(TalentProxyConstant.RESET_TALENT,event.param);
		}
		/**
		 *激活天赋 
		 * @param event
		 * 
		 */
		private function onActivitateHandler(event:TalentEvent):void
		{
			this.sendNotification(TalentProxyConstant.ACTIVATE_TALENT,event.param);
		}
		/**
		 * 删除事件 
		 * 
		 */
		override public function removeEventListeners():void
		{
			
		}
		/**
		 * 监听信息
		 * @return 
		 * 
		 */		
		override public function listNotificationInterests():Array
		{
			return [TalentProxyConstant.GET_ACTIVATE_TALENT,
					TalentProxyConstant.GET_RESET_TALENT,
					TalentProxyConstant.GET_TALENT_INFO];
		}
		/**
		 * 处理信息
		 * @param notification
		 * 
		 */		
		override public function handleNotification(notification:INotification):void
		{
			switch(notification.getName())
			{
				case TalentProxyConstant.GET_ACTIVATE_TALENT:
					
					break;
				case TalentProxyConstant.GET_RESET_TALENT:
					
					break;
				case TalentProxyConstant.GET_TALENT_INFO:
					
					break;
				
			}
		}
		/**
		 * 
		 * 注册
		 */		
		override public function onRegister():void
		{
			resName = ResourceConst.TALENT_SWF;
			if(ResourceManager.instance.isContainResource(ResourceConst.TALENT_SWF))
			{
				showUI();
			}
			else
			{
				loader = new QueueLoader();
				var clubConfig :XML = XML(ResourceManager.instance.getResource(ResourceConst.MODULE_RES_CONFIG)).talent[0];
				var releaseVersion :String;
				for each(var item :XML in clubConfig.item)
				{
					releaseVersion = "?" + item.@version + "." + item.@itemType;
					loader.addQueue(new QueueVo(item.@resName,item.@id,item.@id),item.@url + releaseVersion);
				}
				loadRes();
			}
		}
		/**
		 *加载资源完毕 
		 * @param e
		 * 
		 */		
		override protected function onLoadComplete(e:QueueLoaderEvent):void
		{
			showUI();
			super.onLoadComplete(e);
			ResourceManager.instance.putResource(ResourceConst.TALENT_SWF,resList)
		}
		private function showUI():void
		{
			var cView :IModuleView = Reflection.createInstance("com.lz.football.module.club.ClubView");
			cView.initUI();
			viewComponent = cView;
			GlobalDef.GameContainer.addChild(viewComponent as DisplayObject);
			addEventListeners();
		}
		/**
		 * 删除 mediator
		 * 
		 */		
		override public function removeMediator():void
		{
			facade.removeMediator(MediatorName);
		}
		/**
		 *删除 清理 
		 * 
		 */		
		override public function onRemove():void
		{
			super.onRemove();
			removeEventListeners();
			(viewComponent as IModuleView).destroyView();
			viewComponent = null;
		}
	}
}